<?php

namespace App\Http\Controllers;

use App\MidAutumnIntegral;
use App\MidAutumnLog;


/**
 * Class MidAutumnController
 * @package App\Http\Controllers
 */
class MidAutumnController extends Controller
{

    private $user_id;

    /**
     * MidAutumnController constructor.
     */
    public function __construct()
    {
        $this->middleware('has.token');
        $this->user_id = hashid_decode(request('token'));
    }

    /**
     * 进入游戏
     * @return \Illuminate\Http\JsonResponse
     */
    public function gameIndex()
    {
        return response()->json(MidAutumnIntegral::GameIndex($this->user_id));
    }

    /**
     * 开始游戏
     * @return \Illuminate\Http\JsonResponse
     */
    public function startGame()
    {
        return response()->json(MidAutumnIntegral::StartGame($this->user_id));
    }

    /**
     * 增加分数
     * @return \Illuminate\Http\JsonResponse
     */
    public function addIntegral()
    {
        return response()->json(MidAutumnIntegral::AddIntegral($this->user_id));
    }

    /**
     * 吃了坏东西
     * @return \Illuminate\Http\JsonResponse
     */
    public function endGame()
    {
        return response()->json(MidAutumnIntegral::EndGame($this->user_id));
    }

    /**
     * 抽奖
     * @return \Illuminate\Http\JsonResponse
     */
    public function luckDraw()
    {
        //是否在活动期间
//        if (!$day = MidAutumnLog::Days()) {
//            return response()->json(error('不在活动期间哦'));
//        }
        //是否有抽奖次数
        if (MidAutumnLog::LuckDrawTimes($this->user_id) <= 0) {
            return response()->json(error('您已经没有抽奖次数了'));
        }

        return response()->json(MidAutumnLog::Draw($this->user_id));
    }

    /**
     * 获奖记录
     * @return \Illuminate\Http\JsonResponse
     */
    public function drawList()
    {
        return response()->json(MidAutumnLog::DrawList());
    }
}
